package com.hwhhhh.mygrad;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;

import android.os.Bundle;

import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.hwhhhh.mygrad.adapter.MessageViewpagerAdapter;

public class MessageActivity extends BaseActivity {
    public static final int MENTION = 0;
    public static final int REPLY = 1;
    public static final int LIKE = 2;
    public static final int PRIVATE = 3;

    private ViewPager2 viewpager;
    private TabLayout tabLayout;
    private String[] tabTitles = new String[] {"提到我的", "评论回复", "点赞", "私信"};

    @Override
    protected void initView() {
        viewpager = findViewById(R.id.message_viewpager);
        tabLayout = findViewById(R.id.message_tab_layout);
    }

    @Override
    protected int initLayout() {
        return R.layout.activity_message;
    }

    @Override
    protected void initData() {
        // 给viewpager设置适配器
        viewpager.setAdapter(new MessageViewpagerAdapter(this));
        // 实现TabLayout和ViewPager的联动
        new TabLayoutMediator(tabLayout, viewpager, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(tabTitles[position]); // 设置TabLayout的标签名
            }
        }).attach();
    }
}